package com.atguigu.tingshu.album.test;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/***
 * java集合
 */
public class Demo1 {

    /**
     * 种类: List Map Set
     * @param args
     */
    public static void main(String[] args) {
//        //ArrayList
//        Vector list1 = new Vector();
//        for (int i = 0; i < 100; i++) {
//            new Thread(()->{
//                list1.add(UUID.randomUUID().toString());
//                list1.get(0);
//                System.out.println(list1);
//            }).start();
//        }
//        //LinkedList
//        List list2 = new LinkedList();
//        //CopyOnWriteArrayList
//        List list3 = new CopyOnWriteArrayList();
        Demo1 demo1 = new Demo1();
        new Thread(()->{
            Demo1.b2();
        }, "线程A").start();
        new Thread(()->{
            Demo1.b1();
        }, "线程B").start();
    }

    /**
     * 锁: 在堆里面---对象头(Mark_Word--->64位--->1位偏向锁标识位(0/1) 2位-锁标识位(01/10/00) 4位(1111)年龄15岁晋升老年代
     * --->无锁 偏向锁 轻量级锁 重量级锁)?
     * --自旋锁 /自适应自旋锁--?
     * --隐式可重入?
     * CMS
     * G1
     * ZGC
     */
    public synchronized void a(){
        try {
            System.out.println(Thread.currentThread().getName() + "获取到了锁");
            Thread.sleep(100000);
        }catch (Exception e){

        }
    }

    /**
     * 锁: 方法区
     */
    public synchronized static void b1(){
        try {
            System.out.println(Thread.currentThread().getName() + "获取到了锁");
            Thread.sleep(100000);
        }catch (Exception e){

        }
    }

    public synchronized static void b2(){
        try {
            System.out.println(Thread.currentThread().getName() + "获取到了锁");
            Thread.sleep(100000);
        }catch (Exception e){

        }
    }

    public void c(){
        Object o = new Object();
        synchronized (o){

        }
    }
}
